<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru"> 
    <head>
	<title>LocalCRM</title>
	<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="js/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
	<script src="js/jquery.blockUI.js" type="text/javascript"></script>
	<script src="js/jquery.contextMenu.js" type="text/javascript"></script>

	<script src="js/i18n/grid.locale-ru.js" type="text/javascript"></script>
	<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

	<script src="js/crm/common.js" type="text/javascript"></script>
	<link href="css/redmond/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
	<link href="css/jquery.contextMenu.css" rel="stylesheet" type="text/css"/>
	<link href="css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
    </head>
    <body style="display:none;">
	<script type="text/javascript">
	{literal}
	<!--
	$(document).ready
	(
	    function()
	    {
		$('span#toggle-legend')
		    .css('cursor','pointer')
		    .toggle
		    (
			function() {$(this).text('- Скрыть легенду').next().slideDown('fast')},
			function() {$(this).text('+ Показать легенду').next().slideUp('fast')}
		    );

		$('span#toggle-print-options')
		    .css('cursor','pointer')
		    .toggle
		    (
			function() {$(this).text('- Скрыть').next().slideDown('fast')},
			function() {$(this).text('+ Дополнительно').next().slideUp('fast')}
		    );

		$('a.delete-link').click
		(
		    function()
		    {
			if ( !window.confirm('Вы уверены?') )
			{
			    return false;
			}
		    }
		);

		function checkBoxes()
		{
		    if ( $('input.customer-check:checked').size()==$('input.customer-check').size() )
		    {
			$('input:checkbox#select-all').attr('checked',true);
		    }
		    else
		    {
			$('input:checkbox#select-all').attr('checked',false);
		    }

		    return $('input.customer-check:checked').size();
		}

		if ( checkBoxes()>0 )
		{
		    $('center#toolbar').show();
		}
		else
		{
		    $('center#toolbar').hide();
		}

		$('input:checkbox.customer-check').click
		(
		    function()
		    {
			$.getJSON
			(
			    'customer.php',
			    {
				'do':		$(this).attr('checked')?'select':'deselect',
				'customer':	$(this).val()
			    }
			);

			if ( checkBoxes()>0 ) { $('center#toolbar:hidden').show(); }
			else { $('center#toolbar:visible').hide(); }
		    }
		);

		$('input:checkbox#select-all').click
		(
		    function()
		    {
			if ( $(this).attr('checked') )
			{
			    $('input.customer-check').attr('checked',true);

			    if ( $('input.customer-check').size()>0 )
			    {
				$('center#toolbar:hidden').show();
			    }

/*
			    if ( window.confirm('Нажмите ОК, чтобы отметить все записи в БД, а не только на этой странице') )
			    {
				$.getJSON
				(
				    'customer.php',
				    { 'do': 'select' }
				);
			    }
			    else
			    {
*/
				$('input:checkbox.customer-check').each
				(
				    function()
				    {
					$.getJSON
					(
					    'customer.php',
					    {
						'do':		'select',
						'customer':	$(this).val()
					    }
					);
				    }
				);
/*
			    }
*/
			}
			else
			{
			    $('input.customer-check').attr('checked',false);

			    $.getJSON
			    (
				'customer.php',
				{ 'do': 'deselect' }
			    );
			}
		    }
		);

		$('input:button#action-submit').click
		(
		    function()
		    {
			switch( $('select#action').val() )
			{
			    case	'print':
				$('#document-period')
				    .dialog('option','title','Печать документов')
				    .dialog('option','resizable',false)
				    .dialog
				    (
					'option',
					'buttons',
					{
					    'Скачать архив':	function()
								{
								    $('input#dateYear').val($('#document-year').val());
								    $('input#dateMonth').val($('#document-month').val());
								    $('form#customer-list')
									.attr('action','/cgi-bin/print.cgi')
									.submit();
								}
					}
				    )
				    .find('form')
					.find('.document-add')
					    .show()
					    .end()
					.find('.document-make')
					    .hide()
					    .end()
					.end()
				    .dialog('open');
				break;

			    case	'documents-send':
				window.location.href = 'mail.php';
/*
				$('#document-period')
				    .dialog('option','title','Отправка документов')
				    .dialog('option','resizable',false)
				    .dialog
				    (
					'option',
					'buttons',
					{
					    'Отправить документы':	function()
								{
								    $('input#dateYear').val($('#document-year').val());
								    $('input#dateMonth').val($('#document-month').val());
								    $('form#customer-list')
									.attr('action','document-send.php')
									.submit();
								}
					}
				    )
				    .find('form')
					.find('.document-add')
					    .show()
					    .end()
					.find('.document-make')
					    .hide()
					    .end()
					.end()
				    .dialog('open');
*/
				break;

			    case	'documents-make':
				$('#document-period')
				    .dialog('option','title','Формирование документов')
				    .dialog('option','resizable',false)
				    .dialog
				    (
					'option',
					'buttons',
					{
					    'Формировать':	function()
								{
								    $('form#customer-list')
									.attr('action','document-make.php')
									.submit();
								}
					}
				    )
				    .find('form')
					.find('.document-add')
					    .hide()
					    .end()
					.find('.document-make')
					    .show()
					    .end()
					.end()
				    .dialog('open');
				break;

			    case	'invoice-remake':
				$('#document-period')
				    .dialog('option','title','Перевыставление счетов')
				    .dialog('option','resizable',false)
				    .dialog
				    (
					'option',
					'buttons',
					{
					    'Перевыставить':	function()
								{
								    if ( window.confirm('Уверены?') )
								    {
									$('form#customer-list')
									    .attr('action','invoice-remake.php')
									    .submit();
								    }
								}
					}
				    )
				    .find('form')
					.find('.document-add')
					    .hide()
					    .end()
					.find('.document-make')
					    .show()
					    .end()
					.end()
				    .dialog('open');
				break;
/*
				$('form#customer-list')
				    .attr('action','document-make.php')
				    .submit();
				break;
*/
			}
		    }
		);

		$('a#fields-tune').click
		(
		    function()
		    {
			$('div#fields')
			    .dialog('option','title','Настройка отображения')
			    .dialog('option','resizable',false)
			    .dialog
			    (
				'option',
				'buttons',
				{
				    'Сохранить':	function(){$(this).find('form').submit();}
				}
			    )
			    .dialog('open');
		    }
		);

		$('a#debug-toggle').click(function(){$('div#debug').slideToggle();});

		$('body').show();
	    }
	);
	-->
	{/literal}
	</script>

{* Подключаем основное верхнее меню-слайдер *}
{include file="admin/submodules/_menu.html"}

{* Подключение блока тайм-менеджмента *}
{if $smarty.session.manager.is_admin==1}
    {include file="admin/submodules/tmanagement.dialog.html"}
{/if}

{* Подключаем показатели *}
{if $smarty.session.manager.is_admin==1}
    {include file="admin/submodules/chart.dialog.html"}
{/if}

	<table width="98%" align="center">
	    <tr>
		<td valign="top">
		    {* Подключение блока фильтров клиентов *}
		    {include file="admin/submodules/cfilter.module.html"}
		</td>
		<td valign="top" width="60%">
		    {* Подключение блока работы с задачами *}
		    {include file="admin/submodules/task.module.html}
		</td>
	    </tr>
	</table>

	<hr/>

<!-- Окно выбора периода для работы с документами -->
	<div class="dialog" id="document-period">
	    <form method="get" id="customer-list">
		<p class="document-add">
		    {html_select_date display_days=false start_year=2009 month_extra='id="document-month"' year_extra='id="document-year"'}
		</p>

		<p class="document-make">
		    Дата выставления документов:
		    <input type="text" class="date" name="make_date"/>
		</p>

		<fieldset class="document-add">
		    <legend>Исполнители</legend>
	    {foreach name=executives from=$executives item=executive}
		    <input type="checkbox" name="executive[]" value="{$executive.id}" id="executive_{$executive.id}"/><label for="executive_{$executive.id}">{$executive.executive_name|sslash}</label>{if $smarty.foreach.executives.last==false}<br/>{/if}
	    {/foreach}
		</fieldset>
		<p class="document-add">
		    <input type="checkbox" name="detail" id="detail"/><label for="detail">Печатать детализацию</label>
		</p>
		<input type="hidden" name="dateYear" id="dateYear"/>
		<input type="hidden" name="dateMonth" id="dateMonth"/>
	    </form>
	</div>

<!-- Меню действий // Появляется только если выделен хотя бы один клиент -->
	<center style="display: none;" id="toolbar">
	    С отмеченными:
	    <select id="action">
		<option value="">&mdash;</option>
		<option value="print">Напечатать</option>
		<option value="documents-send">Отправить оповещение/документы</option>
		<option value="documents-make">Сформировать отчетные документы</option>
		<option value="invoice-remake">Перевыставить счета</option>
	    </select>
	    <input type="button" value="&raquo;" id="action-submit"/>
	</center>

<!-- Окно настриваемых полей -->
    <div class="dialog" id="fields">
	Отображаемые поля:
	<form action="db.php" method="post">
	    <input type="hidden" name="action" value="manager.set_fields.do">
	    <table>
{foreach from=$defaults item=field}
		<tr>
		    <td>{$field.title}</td>
		    <td align="center"><input type="checkbox" name="{$field.name}" value="1" {if $smarty.session.manager.options.fields.customer_list[$field.name]==true}checked{/if}/></td>
		</tr>
{/foreach}
		<tr><td colspan="2"><hr/></td></tr>
{foreach from=$customs item=field}
		<tr>
		    <td>{$field.title}</td>
		    <td align="center"><input type="checkbox" name="{$field.name}" value="1" {if $smarty.session.manager.options.fields.customer_list[$field.name]==true}checked{/if}/></td>
		</tr>
{/foreach}
	    </table>
	</form>
    </div>

<!--
/*
#	ТАБЛИЦА СПИСКА КЛИЕНТОВ
*/
-->
{assign var=f_count value=$smarty.session.manager.options.fields.customer_list|@count}

	<table id="customers" class="ui-widget ui-corner-top" width="100%" cellspacing="0" rules="all" style="border: solid 1px #000000;">
	    <thead class="ui-widget-header">
		<tr id="customer-header">
		    <th {if $smarty.session.filter.customer_list.show_deleted==1 && $smarty.session.filter.customer_list.only_deleted==1}colspan="2"{/if}><a href="?action=customer.new"><img src="images/icons/plus_16.png" title="Добавить клиента" border="0"/></a></th>
{if empty($smarty.session.filter.customer_list.only_deleted)}
		    <th><input type="checkbox" id="select-all" title="Выбрать всех" {if $smarty.session.select.customer=='all'}checked{/if}/></th>
{/if}
{foreach from=$defaults item=field}
    {if $smarty.session.manager.options.fields.customer_list[$field.name]==1}
	{if $field.name=='contact'}
		    <th colspan="2">Контактная информация</th>
	{else}
		    <th>{$field.title}</th>
	{/if}
    {/if}
{/foreach}
{foreach from=$customs item=field}
    {if $smarty.session.manager.options.fields.customer_list[$field.name]==1}
		    <th>{$field.title}</th>
    {/if}
{/foreach}
		</tr>
	    </thead>
	    <tbody>
{foreach from=$customers item=customer name=customers}
{*
		<tr {if $smarty.foreach.customers.iteration is even}bgcolor="#f0f0ff"{/if} style="word-wrap: break-word;" {if $customer.documents_total<4}class="ui-state-error"{elseif $customer.documents_total>=4 && $customer.documents_total>$customer.documents_printed}class="ui-state-higlight"{/if}>
*}
		<tr style="word-wrap: break-word;" {if $smarty.foreach.customers.iteration is even}bgcolor="#f0f0ff"{/if}
		{if not empty($customer.is_deleted)}
		    class="ui-state-disabled"
		{else}
		    {if is_numeric($smarty.session.filter.customer_list.executive_id) && $customer.documents_total==0}
		    class="ui-state-error"
		    {elseif is_numeric($smarty.session.filter.customer_list.executive_id) && ($customer.documents_printed<$customer.documents_total)}
		    class="ui-state-higlight"
		    {/if}
		{/if}>
{if empty($customer.is_deleted)}
		    <td align="center">
			<a href="customer-delete.php?id={$customer.id}" class="delete-link">
			    <img src="images/icons/delete_16.png" border="0" title="Удалить"/>
			</a>
		    </td>
		    <td align="center">
			<input type="checkbox" class="customer-check" name="customer[]" value="{$customer.id}" id="customer_{$customer.id}" {if $smarty.session.select.customer[$customer.id]==1 || $smarty.session.select.customer=='all'}checked{/if}/>
		    </td>
{else}
		    <td align="center" colspan="2" title="Удален {$customer.is_deleted|date_format:'%d.%m.%Y'}"><i>[удален]</i></td>
{/if}
{foreach from=$smarty.session.manager.options.fields.customer_list item=field key=field_name}
    {if $field_name=='customer_name'}
		    <td style="padding-left: 1em;"><a href="customer-view.php?id={$customer.id}">{$customer[$field_name]|sslash|default:'&mdash;'}</a></td>
    {elseif $field_name=='contact'}
	{if $customer.contact_phone!='' || $customer.contact_name!=''}
	    {if $customer.contact_phone!=''}<td {if $customer.contact_name==''}colspan="2"{/if} align="center"><span class="tel-number">{$customer.contact_phone}</span></td>{/if}
	    {if $customer.contact_name!=''}<td {if $customer.contact_phone==''}colspan="2"{/if} style="padding-left: 1em;">{$customer.contact_name}{if $customer.contact_post!=''}&nbsp;<i>({$customer.contact_post})</i>{/if}</td>{/if}
	{else}
		    <td colspan="2" align="center"><i>Контактная информация не указана, <a href="customer-edit.php?id={$customer.id}#contact">указать</a></i></td>
	{/if}
    {elseif $field_name=='contract_number'}
		    <td align="center"><strong>{$customer.contract_number|default:'&mdash;'}</strong>{if $customer.contracts_total>1}&nbsp;<sup title="Всего объектов данного типа: {$customer.contracts_total}">{$customer.contracts_total}</sup>{/if}</td>
    {elseif $field_name=='email'}
		    <td align="center" style="max-width: 150px;">{if $customer.email!=''}{mailto address=$customer.email}{else}&mdash;{/if}</td>
    {else}
		    <td align="center">{$customer[$field_name]|default:'&mdash;'}</td>
    {/if}
{/foreach}
		</tr>
{foreachelse}
		<tr><td align="center" colspan="{$f_count+2}">Клиенты не найдены</td></tr>
{/foreach}
	    </tbody>
{if $pages>0}
	    <tfoot>
		<tr>
		    <td align="center" colspan="{$f_count+2}">
    {if $page==1}
			<span class="ui-state-disabled">&nbsp;&laquo;&nbsp;</span>
    {else}
			<span class="ui-state-default"><a href="?page=1">&nbsp;&laquo;&nbsp;</a></span>
    {/if}
			&nbsp;

    {if ($page)>0}
	{math equation=x-1 x=$page assign=prev}
	{if $prev>0}
			<span class="ui-state-default"><a href="?page={$prev}">&nbsp;{$prev}&nbsp;</a></span>
	{/if}
    {/if}
			&nbsp;
			<span class="ui-state-highlight">&nbsp;{$page}&nbsp;</span>
			&nbsp;
    {if ($page+1)<=$pages}
	{math equation=x+1 x=$page assign=next}
			<span class="ui-state-default"><a href="?page={$next}">&nbsp;{$next}&nbsp;</a></span>
    {/if}
			&nbsp;
    {if ($page+1)>$pages}
			<span class="ui-state-disabled">&nbsp;&raquo;&nbsp;</span>
    {else}
			<span class="ui-state-default"><a href="?page={$pages}">&nbsp;&raquo;&nbsp;</a></span>
    {/if}
		    </td>
		</tr>
	    </tfoot>
{/if}
	</table>

	<br/>
	<div class="ui-widget ui-state-disabled">
	    <center>Найдено {$total_rows} записей. Сформировано страниц: {$pages}, записей на страницу: {$limit_rows}</center>
	</div>
	<hr/>
	<br/>
	<a href="javascript:void(0)" id="debug-toggle">показать/скрыть</a> отладочную информацию
	<div id="debug" style="display:none" class="ui-state-default">
	    MySQL Query CUSTOMERS:<p class="ui-state-highlight ui-corner-all" style="border: dashed 1px #000000; padding: 1em;">{$mysql_query_customers}</p>
	    MySQL Query TASKS:<p class="ui-state-highlight ui-corner-all" style="border: dashed 1px #000000; padding: 1em;">{$mysql_query_tasks}</p>
	    $_SESSION:<pre class="ui-state-highlight ui-corner-all" style="border: dashed 1px #000000; padding: 1em;">{php}print_r($_SESSION){/php}</pre>
	</div>
    </body>
</html>
